package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;
import com.hl.sfzy.entity.SysConsultantLevels;
import com.hl.sfzy.entity.SysCourseSort;
import com.hl.sfzy.service.SysConsultantLevelsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class SysConsultantLevelsController {
    @Autowired
    private SysConsultantLevelsService sysConsultantLevelsService;
    /*
     * 新增
     * */
    @PostMapping("/sysConsultantLevels")
    public Result add(@RequestBody SysConsultantLevels sysConsultantLevels){
        int num = sysConsultantLevelsService.add(sysConsultantLevels);
        return num > 0 ? Result.success() : Result.error();
    }
    /*
     * 删除
     * */
    @DeleteMapping("/sysConsultantLevels/{id}")
    public Result remove(@PathVariable("id") Integer id){
        int num = sysConsultantLevelsService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }
    @DeleteMapping("/sysConsultantLevels")
    public Result removeBatch(Integer[] ids){
        int num = sysConsultantLevelsService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();

    }
    /*
     * 修改
     * */
    @PutMapping("/sysConsultantLevels")
    public Result edit(@RequestBody SysConsultantLevels sysConsultantLevels){
        int num = sysConsultantLevelsService.edit(sysConsultantLevels);
        return num > 0 ? Result.success() : Result.error();
    }
    /*
     * 通过id查询
     * */
    @GetMapping("/sysConsultantLevels/{id}")
    public Result findById(@PathVariable("id") Integer id){
        SysConsultantLevels byId = sysConsultantLevelsService.findById(id);
        return Result.success(byId);
    }
    /*
     * 查询所有
     * */
    @GetMapping("/sysConsultantLevels")
    public Result findAll(SysConsultantLevels sysConsultantLevels){
        List<SysConsultantLevels> list = sysConsultantLevelsService.find(sysConsultantLevels);
        return Result.success(list);
    }
    /*
     * 通过page查询
     * */
    @GetMapping("/sysConsultantLevels/page")
    public Result findPage(
            @RequestParam(value = CommonConstant.PAGE_NUM,required = false,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(value = CommonConstant.PAGE_SIZE,required = false,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            SysConsultantLevels sysConsultantLevels) {

        Map<String, Object> map = sysConsultantLevelsService.findPage(pageNum, pageSize, sysConsultantLevels);
        return Result.success(map);
    }
}
